<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 100px;
            height: 100px;
            background-color: springgreen;
            position: absolute;
            top: 100px;
            left: 200px;
        }
        p{
            width: 100px;
            height: 100px;
            background-color: rgb(255, 123, 0);
            position: absolute;
            top: 200px;
            left: 100px;
        }
    </style>
</head>

<body>
    <div></div>
    <p></p>
    <script>
        const box = document.querySelector("div")
        box.onclick = function () {
            /* 移动起始位置,移动位置是哪一个? */
            // let current = 200;
            let current = this.offsetLeft;

            let timer = setInterval(() => {
                current += 5;
                this.style.left = current + "px"
                if(current === 400){
                    clearInterval(timer)
                    timer = null;
                }
            }, 16);
        }
        const p = document.querySelector("p")
        p.onclick = function () {
            /* 移动起始位置,移动位置是哪一个? */
            // let current = 200;
            let current = this.offsetLeft;

            let timer = setInterval(() => {
                current += 5;
                this.style.left = current + "px"
                if(current === 400){
                    clearInterval(timer)
                    timer = null;
                }
            }, 16);
        }
    </script>
</body>

</html>